package thinkingJava.chapter13;

import java.util.Scanner;
import java.util.regex.MatchResult;

public class ThreatAnalyzer {
	static String threatData =
		"58.27.82.162@02/10/2010\n" +
		"202.108.1.105@05/12/2013\n" +
		"61.135.210.83@05/14/2013\n" +
		"61.135.210.83@05/15/2013\n" +
		"[next long section with different data format]";
	public static void main(String[] args) {
		Scanner sc = new Scanner(threatData);
		String pattern = "(\\d+[.]\\d+[.]\\d+[.]\\d+)@" +
				"(\\d{2}/\\d{2}/\\d{4})";
		while (sc.hasNext(pattern)) {
			sc.next(pattern);
			MatchResult m = sc.match();
			String ip = m.group(1);
			String date = m.group(2);
			System.out.format("Threat on %s from %s.\n", date, ip);
		}
	}
}
